package com.ylp.common.response;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "响应数据")
public class Result<T> {

    /**
     * 状态码 0:成功 1: 失败
     */
    @Schema(description = "状态码")
    private int code;
    /**
     * 返回内容
     */
    @Schema(description = "返回内容")
    private String message;
    /**
     * 数据对象
     */
    @Schema(description = "返回数据")
    private T data;

    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <E> Result<E> success() {
        return new Result<>(0, "操作成功", null);
    }

    public static <E> Result<E> success(E data) {
        return new Result<>(0, "操作成功", data);
    }

    public static <E> Result<E> success(String message, E data) {
        return new Result<>(0, message, data);
    }

    public static <E> Result<E> error(String message) {
        return new Result<>(1, message, null);
    }

    public static <E> Result<E> error() {
        return new Result<>(1, "操作失败", null);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
